package com.itheima.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

public class AOPAdvice {

    // 前置通知方法
    public void before(JoinPoint jp){
        // 通过JoinPoint参数获取调用原始方法所携带的参数
        Object[] args = jp.getArgs();
        System.out.println("before..."+args[0]+" "+args[1]);
    }



    // 后置通知
    public void after(JoinPoint jp){
        Object[] args = jp.getArgs();
        System.out.println("after..."+args[0]);
    }

    // 后置返回通知（正常执行）
    public void afterReturning(Object ret){
        System.out.println("after returning..."+ret);
    }

    // 后置异常通知（异常执行）
    public void afterThrowing(Throwable t){
        System.out.println("after throwing..."+t.getMessage());
    }

    // 环绕通知
    public Object around(ProceedingJoinPoint pjp){
        System.out.println("around before...");
        Object ret = null;
        // 对原始方法调用
        try {
            ret = pjp.proceed();
        } catch (Throwable throwable) {
            System.out.println("around...exception..."+throwable.getMessage());
        }
        System.out.println("around after...");
        return ret;
    }

    /*public void before2(){
        System.out.println("before...2");
    }
    public void before3(){
        System.out.println("before...3");
    }*/


}
